/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.zcm.modules.zhaocai.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.zcm.common.web.BaseController;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.zcm.common.config.Global;
import com.zcm.common.persistence.Page;
import com.zcm.common.web.BaseController;
import com.zcm.common.utils.StringUtils;
import com.zcm.modules.zhaocai.entity.ZcmKanpanData;
import com.zcm.modules.zhaocai.service.ZcmKanpanDataService;

/**
 * 看盘数据Controller
 * @author www
 * @version 2018-04-22
 */
@Controller
@RequestMapping(value = "${adminPath}/zhaocai/zcmKanpanData")
public class ZcmKanpanDataController extends BaseController {

	@Autowired
	private ZcmKanpanDataService zcmKanpanDataService;
	
	@ModelAttribute
	public ZcmKanpanData get(@RequestParam(required=false) String id) {
		ZcmKanpanData entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = zcmKanpanDataService.get(id);
		}
		if (entity == null){
			entity = new ZcmKanpanData();
		}
		return entity;
	}
	
	@RequiresPermissions("zhaocai:zcmKanpanData:view")
	@RequestMapping(value = {"list", ""})
	public String list(ZcmKanpanData zcmKanpanData, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<ZcmKanpanData> page = zcmKanpanDataService.findPage(new Page<ZcmKanpanData>(request, response), zcmKanpanData); 
		model.addAttribute("page", page);
		return "modules/zhaocai/zcmKanpanDataList";
	}

	@RequiresPermissions("zhaocai:zcmKanpanData:view")
	@RequestMapping(value = "form")
	public String form(ZcmKanpanData zcmKanpanData, Model model) {
		model.addAttribute("zcmKanpanData", zcmKanpanData);
		return "modules/zhaocai/zcmKanpanDataForm";
	}

	@RequiresPermissions("zhaocai:zcmKanpanData:edit")
	@RequestMapping(value = "save")
	public String save(ZcmKanpanData zcmKanpanData, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, zcmKanpanData)){
			return form(zcmKanpanData, model);
		}
		zcmKanpanDataService.save(zcmKanpanData);
		addMessage(redirectAttributes, "保存看盘数据成功");
		return "redirect:"+Global.getAdminPath()+"/zhaocai/zcmKanpanData/?repage";
	}
	
	@RequiresPermissions("zhaocai:zcmKanpanData:edit")
	@RequestMapping(value = "delete")
	public String delete(ZcmKanpanData zcmKanpanData, RedirectAttributes redirectAttributes) {
		zcmKanpanDataService.delete(zcmKanpanData);
		addMessage(redirectAttributes, "删除看盘数据成功");
		return "redirect:"+Global.getAdminPath()+"/zhaocai/zcmKanpanData/?repage";
	}

}